//
//  LanuchViewController.m
//  Drops
//
//  Created by dllo on 16/5/28.
//  Copyright © 2016年 Drops.er. All rights reserved.
//

#import "LanuchViewController.h"
#import "AppDelegate.h"
#import "ZFK_startTextView.h"
@interface LanuchViewController ()<UIScrollViewDelegate>
{
    //创建页面控制器
    UIPageControl *pageControl;
    //判断是否第一次引入引用
    BOOL flag;
}

@end

@implementation LanuchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIScrollView *myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    for (int i = 0; i < 3; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.pic_hd.jpg",i + 1]];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT)];
        //在最后一页创建按钮
        if (i == 2) {
            //必须设置用户交互 否则按键无法操作
            imageView.userInteractionEnabled = YES;
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(WIDTH / 2 - 50, HEIGHT * 11 / 12, 100, 30);
            [button setTitle:@"点击进入" forState:UIControlStateNormal];
            button.backgroundColor = [UIColor clearColor];
            

            button.frame = CGRectMake(WIDTH / 4, HEIGHT * 6 / 7, WIDTH / 2, HEIGHT / 14);
            [button setTitle:@"点击进入" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.layer.borderWidth = 2;
            button.layer.cornerRadius = 15;
            button.clipsToBounds = YES;
            button.layer.borderColor = [UIColor whiteColor].CGColor;
            [button addTarget:self action:@selector(startGo:) forControlEvents:UIControlEventTouchUpInside];
            [imageView addSubview:button];
        }
        imageView.image = image;
        [myScrollView addSubview:imageView];
    }
    myScrollView.bounces = NO;
    myScrollView.pagingEnabled = YES;
    myScrollView.showsHorizontalScrollIndicator = NO;
    myScrollView.contentSize = CGSizeMake(WIDTH * 3, HEIGHT);
    myScrollView.delegate = self;
    [self.view addSubview:myScrollView];
    
    pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH / 3, HEIGHT * 16 / 17, WIDTH / 3, HEIGHT / 17)];

    ZFK_startTextView *firstView = [[ZFK_startTextView alloc] initWithFrame:CGRectMake(0, 20, sWIDTH, sHEIGHT / 2)];
    firstView.topLabel.text = @"点亮生活";
    firstView.bottomLabel.text = @"旅途不止一种色彩";
    [myScrollView addSubview:firstView];
    ZFK_startTextView *secondView = [[ZFK_startTextView alloc] initWithFrame:CGRectMake(sWIDTH, 20, sWIDTH, sHEIGHT / 2)];
    secondView.topLabel.text = @"滴水不漏";
    secondView.bottomLabel.text = @"精彩照片随心拍";
    [myScrollView addSubview:secondView];
    ZFK_startTextView *thirdView = [[ZFK_startTextView alloc] initWithFrame:CGRectMake(sWIDTH * 2, 20, sWIDTH, sHEIGHT / 2)];
    thirdView.topLabel.text = @"世界那么大";
    thirdView.bottomLabel.text = @"一起去看看";
    [myScrollView addSubview:thirdView];
    
    pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH / 3, HEIGHT * 15 / 16, WIDTH / 3, HEIGHT / 16)];
    // 设置页数
    pageControl.numberOfPages = 3;
    // 设置页码的点的颜色
    pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    // 设置当前页码的点颜色
    pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    
    [self.view addSubview:pageControl];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    // 计算当前在第几页
    pageControl.currentPage = (NSInteger)(scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width);
}

// 点击按钮保存数据并切换根视图控制器
- (void) startGo:(UIButton *)sender{
    flag = YES;
    NSUserDefaults *useDef = [NSUserDefaults standardUserDefaults];
    [useDef setBool:flag forKey:@"notfirst"];
    [useDef synchronize];
    //切换视图控制器
    self.block();
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
